import {Controller, Get, Post, Body, Param, Delete, HttpCode, HttpStatus, Put} from '@nestjs/common';
import {ManageService} from "@src/modules/Survey/services/manage.service";
import {ApiOperation, ApiTags} from "@nestjs/swagger";
import {SurveyEntity} from "@src/modules/Survey/entities/Survey.entity";
import {CreateSurveyDto} from "../dto/CreateSurveyDto";


@ApiTags("调查问卷管理")
@Controller('manage')
export class ManageController {
  constructor(private readonly manageService: ManageService) {
  }

  @ApiOperation({summary: '获取所有问卷', description: '获取所有问卷'})
  @Get()
  @HttpCode(HttpStatus.CREATED)
  async findAllSurvey(): Promise<SurveyEntity[]> {
    return this.manageService.findAllSurvey();
  }


  @ApiOperation({summary: '新增问卷', description: '新增问卷'})
  @Post()
  @HttpCode(HttpStatus.CREATED)
  async createSurveyWithQuestionsAndOptions(
    @Body() createSurveyDto: CreateSurveyDto,
  ): Promise<SurveyEntity> {
    console.log("createSurveyDto", createSurveyDto)
    return this.manageService.createSurveyWithQuestionsAndOptions(createSurveyDto);
  }


  @ApiOperation({summary: '更新问卷', description: '根据问卷id更新问卷'})
  @Put(':surveyId')
  @HttpCode(HttpStatus.CREATED)
  async updateSurvey(
    @Param('surveyId') surveyId: string,
    @Body() updateSurveyDto: CreateSurveyDto,
  ): Promise<void> {
    return this.manageService.updateSurveyById(surveyId, updateSurveyDto);
  }


  @ApiOperation({summary: '删除问卷', description: '根据问卷id删除问卷'})
  @Delete(':surveyId')
  @HttpCode(HttpStatus.CREATED)
  async deleteSurvey(@Param('surveyId') surveyId: string): Promise<void> {
    return this.manageService.deleteSurveyById(surveyId);
  }
}
